import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-08-10
 * Time: 19:18
 */
public class MyStack {
    int[] array;
    int size;

    public MyStack() {
        array = new int[3];
    }

    public void push(int e) {
        if (isFull()){
            this.array=Arrays.copyOf(array,2*array.length);
        }
        array[size++]=e;
    }

    public int pop(){
        if(isEmpty()){
            throw new EmptyStackException();
        }
        int val=array[size-1];
        size--;
        return val;
    }

    public int peek(){
        if(isEmpty()){
            throw new EmptyStackException();
        }
        return array[size-1];
    }

    public boolean isFull() {
        return size==array.length;
    }

    public boolean isEmpty(){
        return size==0;
    }

    public int size(){
        return this.size;
    }

    public void display(){
        for (int i = 0; i < size; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
    }
}